import datetime
import os.path
import sys

from selenium import webdriver
from selenium.webdriver import ActionChains, Keys
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common import keys

class Driver:
    driver = ""
    def __init__(self):
        #创建浏览器驱动对象
        options = webdriver.ChromeOptions()
        self.driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
        self.driver.implicitly_wait(2)


    def GetScreenShot(self):
        #截图功能
        #先创建目录
        dirname = datetime.datetime.now().strftime('%Y-%m-%d')
        if not os.path.exists("../image/"+dirname):
            os.mkdir("../image/"+dirname)

        filename = sys._getframe().f_back.f_code.co_name+"-"+datetime.datetime.now().strftime("%Y-%m-%d-%H%M%S")+".png"

    def clear(self, element):
        #清空指定输入框的内容
        actions = ActionChains(self.driver)
        actions.click(element)
        actions.key_down(Keys.CONTROL).send_keys("a").key_up(Keys.CONTROL) # ctrl + a
        actions.send_keys(keys.DELETE)  #删除
        actions.perform()   #执行所有动作

chromeDriver = Driver()